
//
//  JQHomeCollectionViewCell.m
//  JQJQLive
//
//  Created by Bruce on 20/8/12.
//  Copyright © 2020年 JQLive. All rights reserved.
//

#import "JQHomeCollectionViewCell.h"
#import "UIView+Extension.h"
//#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#import "JQHomeLiveListModel.h"
@interface JQHomeCollectionViewCell()
@property (nonatomic, strong) UILabel *hotLb;
@property (nonatomic, strong) UIImageView *defalutImageV;
@end

@implementation JQHomeCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, (SCREEN_WIDTH - 26) / 2, (SCREEN_WIDTH - 26) *98/174/ 2)];
        [self.imageView setUserInteractionEnabled:true];
        [self addSubview:self.imageView];
        
        self.imageView.contentMode = UIViewContentModeScaleAspectFit;
        self.imageView.clipsToBounds = YES;
        
        self.imageView.backgroundColor = kColorWithHex(0xD0D6EF);//[UIColor grayColor];
        
        self.defalutImageV = [[UIImageView alloc] init];
        [self.imageView addSubview:self.defalutImageV];
        MY_WEAK;
        [self.defalutImageV mas_makeConstraints:^(MASConstraintMaker *make) {
            MY_STRONG;
            make.center.equalTo(strongSelf.imageView);
            make.size.mas_equalTo(CGSizeMake(63,62));
        }];
        self.defalutImageV.image = [UIImage imageNamed:@"home_liveIcon_nor"];
        
        //      home_show_hot
        UIImageView *hotImageV = [[UIImageView alloc] initWithFrame:CGRectMake(8, self.imageView.size.height-18, 10, 12)];
        [self.imageView addSubview:hotImageV];
        hotImageV.image = [UIImage svgImageNamed:@"home_show_hot" size:CGSizeMake(10, 12)];
        
        UILabel *hotLb = [[UILabel alloc] init];
        [self.imageView addSubview:hotLb];
        [hotLb mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(hotImageV);
            make.left.mas_equalTo(hotImageV.mas_right).offset(8);
            make.height.equalTo(@(17));
        }];
        hotLb.textColor = [UIColor whiteColor];
        hotLb.font = [UIFont systemFontOfSize:12];
        self.hotLb = hotLb;
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, (SCREEN_WIDTH - 26) *98/174/ 2+6, (SCREEN_WIDTH - 26) /2-16, 20)];
        self.titleLabel.textAlignment = NSTextAlignmentLeft;
        self.titleLabel.textColor = MYColor3;
        self.titleLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:self.titleLabel];
        
        self.descLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, (SCREEN_WIDTH - 26) *98/174/ 2+20+6+1, (SCREEN_WIDTH - 26) / 2-16, 17)];
        self.descLabel.textAlignment = NSTextAlignmentLeft;
        [self addSubview:self.descLabel];
        self.descLabel.textColor = MYColor9;
        self.descLabel.font = [UIFont systemFontOfSize:12];
        
        [self round:10 RectCorners:UIRectCornerTopLeft|UIRectCornerTopRight|UIRectCornerBottomLeft|UIRectCornerBottomRight];
        
        // 测试代码
//        UITextField *textFL = [[UITextField alloc] initWithFrame:CGRectMake(20, 20, 80, 40)];
//        textFL.backgroundColor = [UIColor redColor];
//        [self addSubview:textFL];
        
    }
    return self;
}
- (void)setRowModelWith:(JQHomeLiveListRows *)data{
//    [self.imageView sd_setImageWithURL:[NSURL URLWithString:data.screenshot_url] placeholderImage:[UIImage svgImageNamed:@"home_liveIcon_nor" size:self.imageView.size]];
//    [self.imageView sd_setImageWithURL:[NSURL URLWithString:data.screenshot_url] placeholderImage:[UIImage imageNamed:@"home_liveIcon_nor"]];
    
    
    
//    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:data.screenshot_url]];
//
//    if (imageData) {
        [self.imageView sd_setImageWithURL:[NSURL URLWithString:data.screenshot_url] placeholderImage:[UIImage imageNamed:@"home_liveIcon_nor"]];
        self.defalutImageV.hidden = YES;
//    }else{
//        self.defalutImageV.hidden = NO;
//    }
    
    
    self.titleLabel.text = data.title;
    self.descLabel.text = data.nickname;
    if (data.heat/10000) {
        self.hotLb.text = [NSString stringWithFormat:@"%.2f万", data.heat / 10000.0];
    }else{
        self.hotLb.text = [NSString stringWithFormat:@"%lld", data.heat];
    }
    
}
@end
